// const { asyncRoutes } = require("@/router")

const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const asyncRoutess = [
  //门店管理
  {
    'path': '/storeManagement',
    'component': 'Layout',
    'children': [
      {
        'path': 'storeManagement',
        'component': 'storeManagement',
        'name': 'storeManagement',
        'meta': { 'title': '门店管理', 'icon': 'store', 'roles': ['店长'] }
      }
    ]
  },
  //排班表
  {
    'path': '/rostering',
    'component': 'Layout',
    'children': [
      {
        'path': 'rostering',
        'component': 'rostering',
        'name': 'Rostering',
        'meta': { 'title': '排班表', 'icon': 'table', 'roles': ['editor'] }
      }
    ]
  },
  //人员管理
  {
    'path': '/personnelManagement',
    'component': 'Layout',
    'children': [
      {
        'path': 'personnelManagement',
        'component': 'personnelManagement',
        'name': 'PersonnelManagement',
        'meta': { 'title': '人员管理', 'icon': 'peoples', 'roles': ['admin'] }
      }
    ]
  },
  //个人管理
  {
    'path': '/personalManagement',
    'component': 'Layout',
    'children': [
      {
        'path': 'personalManagement',
        'component': 'personalManagement',
        'name': 'PersonalManagement',
        'meta': { 'title': '个人管理', 'icon': 'user', 'roles': ['admin'] }
      }
    ]
  },

]

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

module.exports = [
  // user login
  {
    url: '/vue-element-admin/user/login',
    type: 'post',
    response: config => {
      const { id } = config.body
      const token = tokens[id]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }
      return {
        code: 20000,
        data: token
      }
    }
  },

  {
    url: '/user/login',
    type: 'post',
    response: () => {
      return {
        "returnValue": 1,
        "data": {
          "id": 1,
          "nickname": "rose",
          "username": "123",
          "storeId": 1,
          "enabled": true,
          "accountNonExpired": true,
          "accountNonLocked": true,
          "credentialsNonExpired": true,
          "authorities": [
            {
              "authority": "[表情]ift-schedule/recommendEmps"
            },
            {
              "authority": "[表情]aff/deleteById"
            },
            {
              "authority": "[表情]aff[表情]veOne"
            },
            {
              "authority": "[表情]ift-schedule[表情]stByWeek"
            },
            {
              "authority": "[表情]ift-schedule/updateSchedule"
            },
            {
              "authority": "[表情]aff/updatePreferByEmp"
            },
            {
              "authority": "[表情]ift-schedule/scheduleByWeek"
            },
            {
              "authority": "[表情]aff/getByName"
            },
            {
              "authority": "[表情]ift-schedule/scheduleByDay"
            },
            {
              "authority": "[表情]aff[表情]st"
            },
            {
              "authority": "[表情]aff/updateOne"
            },
            {
              "authority": "[表情]ift-schedule[表情]stByDay"
            }
          ],
          "roles": [
            {
              "id": 2,
              "name": "店长"
            }
          ]
        },
        "map": {
          "token": "eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIxOGUyOTAzODI1MjY0ZWYxOGQ3NGU3MWI2MTI3YjM5NCIsInN1YiI6IjEyMyIsImlzcyI6InN3cHUiLCJpYXQiOjE2Nzg3NzMxMjd9.Ymvr74TiG_f_emNXEqeBrHZe9gD19bu9LafrSgk0vsydTqY_YQhywbUOUnjSRUtqkabAUzQajW2e1L25jdQFkA"
        }
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  {
    url: '/user/changePassword',
    type: 'post',
    response: _ => {
      return {
        // "returnValue": 1,
        // "data": "密码修改成功，请重新登录！",
        // "map": {}
        "returnValue": 0,
        "msg": "原密码错误，修改失败！",
        "map": {}
      }
    }
  },

  //获取路由
  {
    url: '/user/getRoutes',
    type: 'get',
    response: () => {
      return {
        returnValue: 1,
        data: asyncRoutess,
      }
    }
  }
]
